package com.example.lammy_grape_effect

import android.annotation.SuppressLint
import android.opengl.GLSurfaceView
import android.os.Bundle
import android.view.View
import android.widget.Button
import android.widget.GridView
import android.widget.TextView
import com.example.grape_effect.base.GrapeEffect
import com.example.grape_effect.zzztest.LYAdapter
import com.example.grape_effect.zzztest.LYRender
import com.example.grape_utils.PermissionsActivity
import com.example.grape_effect.zzztest.ProgramDictionary

class MainActivity : PermissionsActivity() , View.OnClickListener {
    private lateinit var glSurfaceView: GLSurfaceView
    private lateinit var gridView: GridView
    private lateinit var textView: TextView
    private lateinit var render: LYRender
    private lateinit var adapter: LYAdapter
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        initClickListener()
        glSurfaceView = findViewById<GLSurfaceView>(R.id.gl_view)
        textView = findViewById(R.id.cur_function)
        gridView = findViewById(R.id.gridView)

        render = LYRender(glSurfaceView)
        adapter = LYAdapter(this)
        render.adapter = adapter
        gridView.adapter = adapter
    }

    override fun onDonePermissionGranted() {
        GrapeEffect.initEffect(applicationContext)
    }
    private fun initClickListener() {
        findViewById<Button>(R.id.transition).setOnClickListener(this)
        findViewById<Button>(R.id.animation).setOnClickListener(this)
        findViewById<Button>(R.id.filter).setOnClickListener(this)
        findViewById<Button>(R.id.effect).setOnClickListener(this)
        findViewById<Button>(R.id.goto_edit).setOnClickListener(this)
    }

    override fun onClick(view: View) {
        when (view.id) {
            R.id.animation -> {
                textView.text = "动画"
                adapter.glProgramList = ProgramDictionary.getAllAnimations()
                adapter.notifyDataSetChanged()

                /***test jni environment start**/
//                var name = editor?.stringFromJNI()
//                LogUtil.e(TAG, "name = " + name)
                /***test jni environment end**/
            }
            R.id.transition -> {
                textView.text = "转场"
                adapter.glProgramList = ProgramDictionary.getAllTransitions()
                adapter.notifyDataSetChanged()
            }
            R.id.filter -> {
                textView.text = "滤镜"
                adapter.glProgramList = ProgramDictionary.getAllFilters()
                adapter.notifyDataSetChanged()
            }
            R.id.effect -> {
                textView.text = "特效"
                adapter.glProgramList = ProgramDictionary.getAllEffects()
                adapter.notifyDataSetChanged()
            }
//            R.id.goto_edit ->{
//                val intent =  Intent("android.intent.action.Edit")
//                startActivity(intent)
//            }

        }
    }
}